package com.lastproject.ejb.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

/**
 * The persistent class for the Topic database table.
 * 
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "Topic.findAll", query = "SELECT t FROM Topic t"),
		@NamedQuery(name = "Topic.findByCatAndSubcat", query = "SELECT t FROM Topic t WHERE t.category = :cat AND t.subcategory = :subcat")

})
public class Topic implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id")
	private int id;

	// //bi-directional many-to-one association to Survey
	// @OneToMany(mappedBy="topic")
	// private List<Survey> surveys;

	// bi-directional many-to-one association to Category
	@ManyToOne
	@JoinColumn(name = "idCategory")
	private Category category;

	// bi-directional many-to-one association Subcategory
	@ManyToOne
	@JoinColumn(name = "idSubcategory")
	private Subcategory subcategory;

	public Topic() {

	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Subcategory getSubcategory() {
		return subcategory;
	}

	public void setSubcategory(Subcategory subcategory) {
		this.subcategory = subcategory;
	}

	@Override
	public String toString() {
		return "Topic [id=" + id + ", category=" + category + ", subcategory="
				+ subcategory + "]";
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Topic)) {
			return false;
		}
		Topic other = (Topic) obj;
		if (category == null) {
			if (other.category != null) {
				return false;
			}
		} else if (!category.equals(other.category)) {
			return false;
		}
		if (id != other.id) {
			return false;
		}
		if (subcategory == null) {
			if (other.subcategory != null) {
				return false;
			}
		} else if (!subcategory.equals(other.subcategory)) {
			return false;
		}
		return true;
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((category.getName() == null) ? 0 : category.getName()
						.hashCode());
		result = prime * result + id;
		result = prime
				* result
				+ ((subcategory.getName() == null) ? 0 : subcategory.getName()
						.hashCode());
		return result;
	}

}
